package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 2020-11-24 09:55
 *
 * https://leetcode-cn.com/problems/merge-sorted-array/
 */
public class _88_合并两个有序数组 {

    public void merge(int[] nums1, int m, int[] nums2, int n) {

        if (nums1 == null || nums2 == null || nums1.length != m + n) {

            return;
        }

        int n1 = m - 1, n2 = n - 1, index = m + n - 1;


        while (n2 >= 0) {

            if (n1 < 0 || nums1[n1] <= nums2[n2]) {

                nums1[index--] = nums2[n2--];
            }else {

                nums1[index--] = nums1[n1--];
            }
        }

    }

}
